﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using DecisionFramework.ServiceProtection;


namespace Tests.DecisionFramework.ServiceProtection
{
    [TestClass]
    public class SampleServiceProtectorTests
    {
        [TestMethod]
        public void SampleServiceProtector_SampleUse_Success()
        {
            // arrange and act
            string securityToken = "some security token converted to string";
            IServiceProtector protector = new SampleServiceProtector();

            protector
                .RequiresValidSecurityToken(securityToken)
                .AndRequiresRoleType(RoleType.Administrator)
                .InOrderToPerform(() =>
                {
                    // this code will be executed if and only if all of the 
                    // preceeding checks are met.
                    // perhaps a call to data access layer.

                });
        }

        [TestMethod]
        public void SampleServiceProtector_SampleUseOfAuthorizationAction_Success()
        {
            // arrange and act
            string securityToken = "some security token converted to string";
            IServiceProtector protector = new SampleServiceProtector();

            protector
                .RequiresValidSecurityToken(securityToken)
                .AndRequiresRoleType(RoleType.Administrator)
                .AndAuthorizedTo(new SampleAuthorizationAction(), null)
                .InOrderToPerform(() =>
                {
                    // this code will be executed if and only if all of the 
                    // preceeding checks are met.
                    // perhaps a call to data access layer.

                });
        }
    }
}
